using AtDevice;
using System;

namespace AtTester
{
    class MainClass
    {
		
        private static string GetSignalStrength(IGSMInterface gsmI)
        {
            double signal = 0.0;
            
            try {
                signal = gsmI.GetSignal() / 100.0;
            } catch(UnknownSignalException) { }
            
            int nbars = AtUtils.GetSignalNumberOfBars(signal);
            
            // Example: [▯▯   ] (32%)
            string strength = String.Format("[{0}{1}] ({2}%)", new String('▯', nbars),
                                                               new String(' ', 5 - nbars),
                                                               signal*100);
            return strength;
        }
		
        public static void Main(string[] args)
        {
            try {
                DeviceHandler.Connect("/dev/ttyUSB2");
            } catch(ApplicationException) {
                Console.WriteLine("Couldn't open /dev/ttyUSB2");
                return;
            }

            IGSMInterface gsmI = DeviceHandler.Get().GetGSMInterface();
			
            Console.WriteLine("Manufacturer:\t\t{0}", gsmI.GetManufacturer());
            Console.WriteLine("Model:\t\t\t{0}", gsmI.GetModel());
            Console.WriteLine("Revision:\t\t{0}", gsmI.GetModelRevision());
            Console.WriteLine("IMEI:\t\t\t{0}", gsmI.GetIMEI());
            Console.WriteLine("IMSI:\t\t\t{0}", gsmI.GetIMSI());
            Console.WriteLine("");
            Console.WriteLine("Operator:\t\t{0}", gsmI.GetNetwork());
            Console.WriteLine("Cell Id:\t\t\t{0}", gsmI.GetCellId());
            Console.WriteLine("Roaming:\t\t{0}", gsmI.IsRoamed() ? "Yes" : "No");
            Console.WriteLine("Network:\t\t{0}", AtUtils.GetNetworkName(gsmI.GetNetworkType()));
            Console.WriteLine("Signal:\t\t\t{0}", GetSignalStrength(gsmI));
			
			DeviceHandler.Close();
        }
    }
}